package com.demo.servlet;

import com.demo.service.BuyGoodService;
import com.demo.service.impl.BuyGoodServiceImpl;
import com.demo.vo.BuyGood;


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

public class BuyGoodServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        BuyGood vo= new BuyGood();
        vo.setGoodName1(request.getParameter("goodName1"));
        vo.setGoodCount1(request.getParameter("goodCount1"));
        vo.setGoodPrice1(request.getParameter("goodPrice1"));

        BuyGoodService buygoodService = new BuyGoodServiceImpl();
        //调用Service层增加方法（add），增加记录
        buygoodService.add(vo);

        HttpSession session = request.getSession();
        session.setAttribute("player", vo);
        response.getWriter().println("<script language= \"javascript\" >\n" +
                "alert( \"购买成功!\" );\n" +
                "top.location= 'menu.jsp' ;\n" +
                "</script>");


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
